import datetime

from sqlalchemy import Column, String, DateTime
from sqlalchemy import Numeric

from database import db


class AdditionalItem(db.Model):
    id = Column(String(40),primary_key=True)
    screen_name = Column(String(80))
    short_name = Column(String(80))
    fee = Column(Numeric(precision=8, scale=4), default=0.00)
    mode = Column(String(20),default='fixed')
    settlement_mode = Column(String(40), default='platform', doc='结算对象')
    created_at = Column(DateTime,default=datetime.datetime.now)
    updated_at = Column(DateTime, default=datetime.datetime.now)

    def calc_amount(self, currency, amount):
        if self.mode == 'fixed':
            return currency.transform_amount(self.fee)
        elif self.mode == 'rate':
            return currency.transform_amount(amount) * self.fee
    # def calculate_amount(self, currency, amount):
    #     from decimal import Decimal
    #     amount = Decimal.from_float(0.00)
    #     if currency:
    #         if self.mode == 'fixed':
    #             amount = self.fee * currency.rate
    #         if self.mode ==
